package db

import (
    "gorm.io/gorm"
    "log"
)

func BeginTransaction() *gorm.DB {
    tx := DB.Begin()
    if tx.Error != nil {
        log.Fatalf("Failed to begin transaction: %v", tx.Error)
    }
    return tx
}

func CommitTransaction(tx *gorm.DB) {
    if err := tx.Commit().Error; err != nil {
        log.Fatalf("Failed to commit transaction: %v", err)
    }
}

func RollbackTransaction(tx *gorm.DB) {
    if err := tx.Rollback().Error; err != nil {
        log.Fatalf("Failed to rollback transaction: %v", err)
    }
}